import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    count: 0,
    num: 0
  },
  getters: {
    double: state => {
      return state.count * 2;
    }
  },
  mutations: {
    tongbu (state, n) {
      state.count += n;
      console.log(state.count);
    },
    yibu (state, n) {
      setTimeout(() => {
        state.num += n;
      }, 2000);
    }
  },
  actions: {
    changeCount ({ commit }, n) {
      setTimeout(() => {
        commit("add", n);
      }, 3000);
    }
  },
  modules: {}
});
